package com.adingxiong.cft.controller.es;

import com.adingxiong.cft.entity.TUser;
import com.adingxiong.cft.result.Result;
import com.adingxiong.cft.service.EsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName EsUserController
 * @Description TODO
 * @Author xiongchao
 * @Date 2021/1/15 10:23
 **/
/*@Api(tags = "用户es高级搜索")
@RequestMapping(value = "/es")
@RestController*/
public class EsUserController {

    @Autowired
    private EsUserService esUserService;


    @PostMapping("/import")
    @ApiOperation(value = "导入所有数据到es中")
    public Result importAll(){
        int i = esUserService.importAll();
        return Result.success(i);
    }

    @GetMapping("/list")
    @ApiOperation(value = "全景检索关键字")
    public Result<Page<TUser>> findByKeywords(
            @ApiParam(value = "关键字") @RequestParam(value = "keywords",required = false) String keywords,
            @ApiParam(value = "pageSize",name = "当前页码") @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize,
            @ApiParam(value = "pageNum",name = "每页条数") @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum
    ){
        Page<TUser> search = esUserService.search(keywords, pageNum, pageSize);
        return Result.success(search);
    }
}
